package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkFeeSubject;
import com.ruoyi.logistic.domain.NetworkFeeSubjectMonth;
import com.ruoyi.logistic.domain.dto.NetworkFeeSubjectDto;
import com.ruoyi.logistic.domain.dto.NetworkFeeSubjectDtoTwo;
import com.ruoyi.logistic.domain.vo.NetworkFeeSubjectVo;
import com.ruoyi.logistic.service.NetworkFeeSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/FeeSubject")
@RestController
@Api(tags = "网点财务_固定费用录入")
public class NetworkFeeSubjectController {
    @Autowired
    private NetworkFeeSubjectService networkFeeSubjectService;

    @ApiOperation("新增科目")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkFeeSubjectDto networkFeeSubject){
        if (networkFeeSubject.getName() == null || networkFeeSubject.getParentId() == null || networkFeeSubject.getLabel() == null){
            return R.fail("参数不足");
        }
        Boolean isAdd = networkFeeSubjectService.insert(networkFeeSubject);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("在线编辑")
    @PostMapping("/update")
    public R update(@RequestBody List<NetworkFeeSubject> networkFeeSubject){
        Boolean isUpdate = networkFeeSubjectService.updateList(networkFeeSubject);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("搜索显示")
    @PostMapping("/search")
    public R search(@RequestBody NetworkFeeSubjectVo vo){
        if (vo.getMonth() == null || vo.getNetworkNameId() == null){
            return R.fail("请传入所需的网点信息和月份信息");
        }
        List<NetworkFeeSubject> networkFeeSubjectList = networkFeeSubjectService.search(vo);
        if (networkFeeSubjectList == null || networkFeeSubjectList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkFeeSubjectList);
        }
    }
    @ApiOperation("一级科目下拉框")
    @GetMapping("/selectOneLevel")
    public R selectOneLevel(){
        List<NetworkFeeSubject> list = networkFeeSubjectService.selectOneLevel();
        if (list == null || list.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(list);
        }
    }

    @ApiOperation("月份信息")
    @GetMapping("/selectMonth")
    public R selectMonth(){
        List<NetworkFeeSubjectMonth> list = networkFeeSubjectService.selectMonth();
        if (list == null || list.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(list);
        }
    }

    @ApiOperation("返回年度金额")
    @GetMapping("/return")
    public R returnAmount(@Param("month") String month,@Param("name") String name){
        return R.ok(networkFeeSubjectService.collectYearAmount(month,name));
    }

}
